(function(n){function t(n){var u=n.originalEvent.changedTouches,t=u[0],i="",r;switch(n.type){case"touchmove":i="mousemove";break;case"touchend":i="mouseup";break;default:return}r=document.createEvent("MouseEvent"),r.initMouseEvent(i,!0,!0,window,1,t.screenX,t.screenY,t.clientX,t.clientY,!1,!1,!1,!1,0,null),t.target.dispatchEvent(r),n.preventDefault()}n.fn.rateit=function(i,r){var u={},e="init",o=function(n){return n.charAt(0).toUpperCase()+n.substr(1)},f;if(this.length==0)return this;if(f=n.type(i),f=="object"||i===undefined||i==null)u=n.extend({},n.fn.rateit.defaults,i);else{if(f=="string"&&r===undefined)return this.data("rateit"+o(i));f=="string"&&(e="setvalue")}return this.each(function(){var h=n(this),f=function(n){return arguments[0]="rateit"+o(n),h.data.apply(h,arguments)},a,s,c,v,y,l,p;if(h.hasClass("rateit")||h.addClass("rateit"),a=h.css("direction")!="rtl",e=="setvalue"){if(!f("init"))throw"Can't set value before init";i!="readonly"||f("readonly")||(h.find(".rateit-range").unbind(),f("wired",!1)),i=="value"&&r==null&&(r=f("min")),f("backingfld")&&(s=n(f("backingfld")),i=="value"&&s.val(r),i=="min"&&s[0].min&&(s[0].min=r),i=="max"&&s[0].max&&(s[0].max=r),i=="step"&&s[0].step&&(s[0].step=r)),f(i,r)}f("init")||(f("min",f("min")||u.min),f("max",f("max")||u.max),f("step",f("step")||u.step),f("readonly",f("readonly")!==undefined?f("readonly"):u.readonly),f("resetable",f("resetable")!==undefined?f("resetable"):u.resetable),f("backingfld",f("backingfld")||u.backingfld),f("starwidth",f("starwidth")||u.starwidth),f("starheight",f("starheight")||u.starheight),f("value",f("value")||u.value||u.min),f("ispreset",f("ispreset")!==undefined?f("ispreset"):u.ispreset),f("backingfld")&&(s=n(f("backingfld")),f("value",s.hide().val()),(s.attr("disabled")||s.attr("readonly"))&&f("readonly",!0),s[0].nodeName=="INPUT"&&(s[0].type=="range"||s[0].type=="text")&&(f("min",parseInt(s.attr("min"))||f("min")),f("max",parseInt(s.attr("max"))||f("max")),f("step",parseInt(s.attr("step"))||f("step"))),s[0].nodeName=="SELECT"&&s[0].options.length>1&&(f("min",Number(s[0].options[0].value)),f("max",Number(s[0].options[s[0].length-1].value)),f("step",Number(s[0].options[1].value)-Number(s[0].options[0].value)))),h.append('<div class="rateit-reset"><\/div><div class="rateit-range"><div class="rateit-selected" style="height:'+f("starheight")+'px"><\/div><div class="rateit-hover" style="height:'+f("starheight")+'px"><\/div><\/div>'),a||(h.find(".rateit-reset").css("float","right"),h.find(".rateit-selected").addClass("rateit-selected-rtl"),h.find(".rateit-hover").addClass("rateit-hover-rtl")),f("init",!0)),c=h.find(".rateit-range"),c.width(f("starwidth")*(f("max")-f("min"))).height(f("starheight")),v="rateit-preset"+(a?"":"-rtl"),f("ispreset")?h.find(".rateit-selected").addClass(v):h.find(".rateit-selected").removeClass(v),f("value")!=null&&(y=(f("value")-f("min"))*f("starwidth"),h.find(".rateit-selected").width(y)),l=h.find(".rateit-reset"),l.data("wired")!==!0&&l.click(function(){f("value",f("min")),c.find(".rateit-hover").hide().width(0),c.find(".rateit-selected").width(0).show(),f("backingfld")&&n(f("backingfld")).val(f("min")),h.trigger("reset")}).data("wired",!0),p=function(t,i){var u=i.changedTouches?i.changedTouches[0].pageX:i.pageX,r=u-n(t).offset().left;return a||(r=c.width()-r),r>c.width()&&(r=c.width()),r<0&&(r=0),y=Math.ceil(r/f("starwidth")*(1/f("step")))},f("readonly")?l.hide():(f("resetable")||l.hide(),f("wired")||(c.bind("touchmove touchend",t),c.mousemove(function(n){var i=p(this,n),t=i*f("starwidth")*f("step"),r=c.find(".rateit-hover"),u;r.data("width")!=t&&(c.find(".rateit-selected").hide(),r.width(t).show().data("width",t),u=[i*f("step")+f("min")],h.trigger("hover",u).trigger("over",u))}),c.mouseleave(function(){c.find(".rateit-hover").hide().width(0).data("width",""),h.trigger("hover",[null]).trigger("over",[null]),c.find(".rateit-selected").show()}),c.mouseup(function(t){var r=p(this,t),i=r*f("step")+f("min");f("value",i),f("backingfld")&&n(f("backingfld")).val(i),f("ispreset")&&(c.find(".rateit-selected").removeClass(v),f("ispreset",!1)),c.find(".rateit-hover").hide(),c.find(".rateit-selected").width(r*f("starwidth")*f("step")).show(),h.trigger("hover",[null]).trigger("over",[null]).trigger("rated",[i])}),f("wired",!0)),f("resetable")&&l.show())})},n.fn.rateit.defaults={min:0,max:5,step:.5,starwidth:16,starheight:16,readonly:!1,resetable:!0,ispreset:!1},n(function(){n("div.rateit").rateit()})})(jQuery)